package main

import "fmt"

/**
操作slice
*/
func main() {

	var numbers = make([]int, 3, 5)
	fmt.Printf("slice numbers len == %d , cap ==%d , value == %v \n", len(numbers), cap(numbers), numbers)
	numbers1 := []int{1, 2, 3}
	fmt.Printf("numbers1 %T %v \n", numbers1, numbers1)
	array := []int{1, 2, 3, 4, 5}
	fmt.Printf("array %T %v , array 长度为%d ,容量为 %d \n", array, array, len(array), cap(array))

	numbers2 := array[1:4]
	fmt.Printf("numbers2 %T %v \n", numbers2, numbers2)

	numbers3 := array[0:]
	fmt.Printf("numbers3 %T %v \n", numbers3, numbers3)

	numbers4 := array[:3]
	fmt.Printf("numbers4 %T %v \n", numbers4, numbers4)

	numbers4[0] = 100
	fmt.Printf("修改值后的  numbers4 %T %v \n", numbers4, numbers4)
	fmt.Printf("修改值后的  array %T %v  \n", array, array)

	//追加元素
	numbers5 := append(array, 600)
	fmt.Printf("numbers5 %T %v \n", numbers5, numbers5)
	fmt.Printf("追加值后的  array %T %v  \n", array, array)
	//追加切片
	appendS1 := []int{6, 7, 8}
	numbers6 := append(array, appendS1...)
	fmt.Printf("numbers6 %T %v \n", numbers6, numbers6)

	//删除第一个元素
	numbers7 := numbers6[1:]
	fmt.Printf("numbers7 %T %v \n", numbers7, numbers7)
	fmt.Printf("删除第一个元素后的 numbers6 %T %v \n", numbers6, numbers6)

	//删除最后一个元素
	numbers8 := numbers6[:len(numbers6)-1]
	fmt.Printf("numbers8  %T %v \n", numbers8, numbers8)
}
